package org.esisar.controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.esisar.controller.utils.SessionHelper;
import org.esisar.dao.AlbumStatementCreator;
import org.esisar.dao.JDBCDAO;
import org.esisar.model.Model;

public class AlbumDisplayController extends HttpServlet {
	
	JDBCDAO jdbcdao = new JDBCDAO();
	
	public void doGet(HttpServletRequest req, HttpServletResponse res) 
			throws ServletException, IOException{
		
		String id = String.valueOf(SessionHelper.getUserId(req));
		
		if (req.getParameter("role") != null){
			
			try {
				List<Model> albums = jdbcdao.findAll(new AlbumStatementCreator(), "idClient", id);

				req.setAttribute("albums", albums);
				
				RequestDispatcher dispatcher;
				if (req.getParameter("addAlbum") != null)
					dispatcher = req.getRequestDispatcher("/Order/AddAlbum.jsp");
				else
					dispatcher = req.getRequestDispatcher("/Album/getAlbums.jsp");
				dispatcher.forward(req, res);

					
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
	}

}
